﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Cwt;

namespace WebApp
{
    public partial class ArticleDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Guid categoryID = new Guid(Request.QueryString["cid"]);
                Guid id = new Guid(Request.QueryString["id"]);

                ICwtService service = Global.Get<ICwtService>();
                Article article = service.FindArticle(id);
                if (article != null)
                {
                    if (categoryID == article.CategoryId)
                    {
                        _ctlCategoryLink.InnerText = article.Category.Caption;
                        InitNavs(article.Category.Code);

                        _ctlTxtTitle.InnerText = article.Title;
                        _ctlTxtAuthor.InnerText = article.Author;
                        _ctlTxtPostedDate.InnerText = article.PostedDate.ToString("yyyy年MM月dd日");
                        _ctlContent.Text = article.Content;
                    }
                    else
                    {
                        Response.Redirect("~/Error.aspx");
                    }
                }
            }
        }

        private void InitNavs(string code)
        {
            if (code == "C001")
            {
                _ctlLinkCourseMenu.Attributes["class"] = "current";
                _ctlLinkCourse.HRef = "#";
            }
            else if (code == "C002")
            {
                _ctlLinkKnowledgeMenu.Attributes["class"] = "current";
                _ctlLinkKnowledge.HRef = "#";
            }
            else if (code == "C003")
            {
                _ctlLinkFAQMenu.Attributes["class"] = "current";
                _ctlLinkFAQ.HRef = "#";
            }
        }
    }
}